package com.bw.ivideoproject.push


import android.widget.ImageView
import android.widget.LinearLayout
import com.bw.ivideoproject.R
import com.bw.ivideoproject.databinding.ActivityPlayBinding
import com.bw.lib_imageutils.ImageLoaderManager
import com.bw.lib_mvvm.BaseActivity
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer


class PlayActivity : BaseActivity<ActivityPlayBinding>() {

    private var videoPath: String = ""
    private var imageView:ImageView ?= null
    private var gsy:StandardGSYVideoPlayer ?= null

    override fun initView() {
        videoPath = intent.getStringExtra("videoPath").toString()
        if(videoPath.contains(".mp4")){
            showVideo()
        }else if(videoPath.contains(".jpg")){
            showPic()
        }
    }

    private fun showPic(){
        imageView = ImageView(this)
        var params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT)
        imageView?.layoutParams = params
        binding.ll.addView(imageView)
        ImageLoaderManager.getInstance().loadFileIntoImageView(this,videoPath,imageView,null)
    }

    private fun showVideo(){
        gsy = StandardGSYVideoPlayer(this)
        var params = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT)
        gsy?.layoutParams = params
        binding.ll.addView(gsy)
        gsy?.setUp(videoPath,true,"")
        gsy?.startButton?.performClick()
        gsy?.backButton?.setOnClickListener {
            finish()
        }
    }

    override fun initData() {

    }

    override fun onDestroy() {
        super.onDestroy()
        imageView = null
        gsy = null
    }

    override fun bindLayout(): Int {
        return R.layout.activity_play
    }

}